package com.qf;

import com.qf.entity.Emp;
import com.qf.mapper.EmpMapper;
import com.qf.utils.MyBatisUtils;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author 10202
 * @version V1.0
 * @Project Day47_again
 * @Package com.qf
 * @Date 2023/4/24 16:10
 */
public class MyBatisDySql {
    @Test
    public void  dySql(){
        EmpMapper mapper = MyBatisUtils.getMapper(EmpMapper.class);
        String name ="    王   ";
        Integer age=14;
        Integer salary=30001;
        if(name!=null){
          name = name.trim();
        }

       List<Emp> emps= mapper.selectBySome(name,age,salary);

        emps.stream().forEach(System.out::println);
    }
    @Test
    public void insertSql(){
        EmpMapper mapper = MyBatisUtils.getMapper(EmpMapper.class);
        List<Emp> empList=new ArrayList<>();
        for (int i = 0; i <2000 ; i++) {
            Emp emp=new Emp();
            emp.setName("nameid="+i);
            emp.setAge(new Random().nextInt(100));
            emp.setSalary(1000+i);
            empList.add(emp);
        }
        try {
            mapper.insertEmp(empList);
            MyBatisUtils.commit();
        } catch (Exception e) {
            e.printStackTrace();
            MyBatisUtils.rollback();
        }

    }



}
